<template>
  <div class="app-container">
    <el-row :gutter="10">
      <fold :span="5" :xs="24" :show.sync='sideshow'>
        <el-card shadow="never">
          <org-tree ref="orgTree" modelType="'dept','community','floor','unit','room'" @nodeClick="handleNodeClick"
            @firstNodeClick="handleNodeClick" />
        </el-card>
      </fold>
      <el-col :span="sideshow ? 19 : 24" :xs="24">
        <el-card shadow="always">
          <el-form :model="queryParams" ref="queryForm" v-show="showSearch" label-width="68px" class="form-flex">
            <el-row :gutter="20">
              <el-col :span="6" :xs="24">
                <el-form-item label="客户名称" prop="customName">
                  <el-input v-model="queryParams.customName" placeholder="请输入客户名称" clearable size="small"
                    @keyup.enter.native="handleQuery" />
                </el-form-item>
              </el-col>
              <el-col :span="6" :xs="24">
                <el-form-item label="收费项目" prop="chargeName">
                  <el-input v-model="queryParams.chargeName" placeholder="请输入收费项目" clearable size="small"
                    @keyup.enter.native="handleQuery" />
                </el-form-item>
              </el-col>

              <el-col :span="6" :xs="24">
                <el-form-item label="收费时间" prop="chargeTime">
                  <el-date-picker clearable size="small" v-model="queryParams.time" type="date"
                    value-format="yyyy-MM-dd" placeholder="选择日期">
                  </el-date-picker>
                </el-form-item>
              </el-col>

              <el-col :span="6" :xs="24">
                <el-form-item>
                  <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                  <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                v-hasPermi="['payfee:balanceRefill:add']">新增</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
          </el-row>

          <el-table sty v-loading="loading" :data="balanceRefillList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="所属房间" align="center" prop="roomName" width="180">
              <template slot-scope="scope">
                {{`${scope.row.roomName}[${scope.row.customName}]`}}
              </template>
            </el-table-column>
            <el-table-column label="收费项目" align="center" prop="chargeName" />
            <el-table-column label="余额" align="center" prop="receiptsMoney" />
            <el-table-column label="更新人" align="center" prop="createBy" />
            <el-table-column label="最后更新时间" align="center" prop="createTime" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button size="mini" type="text" icon="el-icon-tickets" @click="handleHistory(scope.row)"
                  v-if="scope.row.status!='10002'" v-hasPermi="['payfee:balanceRefill:history']">历史记录</el-button>
              </template>
            </el-table-column>
          </el-table>

          <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />
        </el-card>
      </el-col>
    </el-row>
    <BalanceRefillForm ref="formRef" @cancel="getList" />
    <BalanceHistory ref="showHistory"></BalanceHistory>
  </div>
</template>

<script>
  import BalanceRefillForm from "./form.vue"
  import {
    listMixin
  } from "@/utils/mixins/listMixin";
  import {
    listRoomBalance
  } from "@/api/payfee/roomBalance";
  import BalanceHistory from "./history.vue"
  export default {
    name: "BalanceRefill",
    components: {
      BalanceHistory,
      BalanceRefillForm
    },
    mixins: [listMixin],
    dicts: ['collection_method', 'charge_status', ],
    data() {
      return {
        // 余额充值表格数据
        balanceRefillList: [],
        currentNode: {},
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          deptId: null,
          ancestors: null,
          customName: null,
          chargeName: null,
          time: null
        },

      };
    },
    created() {
      let getTime = this.$route.query.time;
      if (getTime != null && getTime == "no") {
        this.queryParams.time = this.parseTime(new Date(), '{y}-{m}-{d}');
      }
      this.getList();
    },
    methods: {
      /** 查询余额充值列表 */
      getList() {
        this.loading = true;
        listRoomBalance(this.queryParams).then(response => {
          this.balanceRefillList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      handleNodeClick(node) {
        console.log("node", node)
        this.currentNode = node;
        this.queryParams.nodeId = node.id
        this.getList()
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.$refs.formRef.show({
          currentNode: this.queryParams.roomId,
          node:this.currentNode,
          type: 'ADD'
        })

      },
      handleHistory(row) {
        console.log(row)
        this.$refs.showHistory.showHistoryPage(row.roomId, row.chargeId);
      }
    }

  };
</script>
